/// <reference types="@vertx/core/runtime" />
// @ts-check

import {BodyHandler, Router} from "@vertx/web";

const {helloHandler, authHandler, createBook, queryBook, queryBook2, updateBook, deleteBook} = require("./router/routes");

const app = Router.router(vertx);

app.route()
  .handler(BodyHandler.create())
  .handler(authHandler)
  .failureHandler(error => {
    console.error(error.failure());
    error.response().end("ERROR");
  });

app.get("/hello").handler(helloHandler);
app.post("/book").handler(createBook);
app.put("/book").handler(updateBook);
app.delete("/book").handler(deleteBook);
app.post("/queryBook").handler(queryBook);
app.post("/queryBook2").handler(queryBook2);

vertx.createHttpServer()
  .requestHandler(app)
  .listen(8090, server => {
    if (server.succeeded()) {
      console.log("server start ", server.result().actualPort());
    } else {
      console.error(server.cause());
    }
  });

